﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Inference
{
	public partial class MakeSubDomain : Form
	{
		TaleEntities tale;
		public string ChosenDomainName
		{
			get
			{
				if (cmbBaseDomain.SelectedIndex != -1)
				{
					return cmbBaseDomain.SelectedItem.ToString();
				}
				return null;
			}
		}

		public MakeSubDomain(string currentDomainName)
		{
			InitializeComponent();

			tale = new TaleEntities();

			LoadCmb(currentDomainName);

			this.Text = "Выбрать объемлющий домен для домена \""+currentDomainName+"\"";
		}

		public void LoadCmb(string except)
		{
			cmbBaseDomain.Items.Clear();

			var doms = tale.Domains.Where(d => d.ID != 1 && d.ID != 7).OrderBy(d => d.Name).ToList();
			foreach (var item in doms)
			{
				if (item.Name != except)
				{
					cmbBaseDomain.Items.Add(item.Name);
				}
			}
			if (cmbBaseDomain.Items.Count == 0)
			{
				cmbBaseDomain.Enabled = false;
			}
			else if (cmbBaseDomain.SelectedIndex == -1)
			{
				cmbBaseDomain.SelectedIndex = 0;
			}

		}
	}
}
